<template>
  <a-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="取消"
  >
    <a-form
      layout="horizontal"
      :form="form"
      :label-col="{ span: 3 }"
      :wrapper-col="{ span: 21 }"
    >
      <a-form-item label="操作">
        <a-select
          placeholder="请选择操作"
          v-decorator="['status', { rules: [{ required: true, message: '请选择操作类型' }] }]"
        >
          <a-select-option v-for="item in actionOptions" :key="item.value" :value="item.value">
            {{ item.label }}
          </a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="备注">
        <a-textarea placeholder="请输入备注" v-decorator="['remark']" :autoSize ="{ minRows: 3, maxRows: 5 }"/>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import Api from '@api/CashManage/FundsWithdrawal'
import { putAction } from '@api/manage'
export default {
  name: 'WithdrawApply',
  data() {
    return {
      title: '提现申请',
      modalWidth: 800,
      visible: false,
      url: {
        audit: Api.sysUserWithdrawalAudit
      },
      actionOptions:[
        { label: '通过', value: 1 },
        { label: '拒绝', value: 2 },
      ],
      form: this.$form.createForm(this),
      record: {}
    }
  },
  created() {},
  methods: {
    // 展示弹窗
    showModal(record) {
      this.visible = true
      this.record = record
      this.$nextTick(() => {
        this.form.setFieldsValue({
          status: undefined,
          remark: ''
        })
      })
    },
    handleOk() {
      this.form.validateFields((err, values) => {
        if (!err) {
          let data = Object.assign({}, this.record, values)
          putAction(this.url.audit, data).then(res => {
            if (res.code === 200) {
              this.$message.success(res.message)
            } else {
              this.$message.error(res.message)
            }
          })
          this.visible = false
          this.$emit('ok')
        }
      })
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.$emit('close')
      this.visible = false
    }
  }
}
</script>

<style lang="less" scoped>
.alert-custom {
  p {
    margin: 0;
  }
  .blue {
    color: #1890ff;
  }
  .green {
    color: #52c41a;
  }

  .red {
    color: #f5222d;
  }
}
</style>

